package com.aiyige.page.photo.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by zhuyakun on 2017/12/20.
 */

public class Photo implements Parcelable {
    public static final int MEDIA_TYPE_PHOTO = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;
    String url;
    String introduction;
    String videoUrl;
    int mediaType;

    public Photo() {
    }

    private Photo(Builder builder) {
        setUrl(builder.url);
        setIntroduction(builder.introduction);
        setVideoUrl(builder.videoUrl);
        setMediaType(builder.mediaType);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    public int getMediaType() {
        return mediaType;
    }

    public void setMediaType(int mediaType) {
        this.mediaType = mediaType;
    }

    public static final class Builder {
        private String url;
        private String introduction;
        private String videoUrl;
        private int mediaType;

        private Builder() {
            url = "";
            introduction = "";
            videoUrl = "";
            mediaType = MEDIA_TYPE_PHOTO;
        }

        public Builder url(String val) {
            url = val;
            return this;
        }

        public Builder introduction(String val) {
            introduction = val;
            return this;
        }

        public Builder videoUrl(String val) {
            videoUrl = val;
            return this;
        }

        public Builder mediaType(int val) {
            mediaType = val;
            return this;
        }

        public Photo build() {
            return new Photo(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.url);
        dest.writeString(this.introduction);
        dest.writeString(this.videoUrl);
        dest.writeInt(this.mediaType);
    }

    protected Photo(Parcel in) {
        this.url = in.readString();
        this.introduction = in.readString();
        this.videoUrl = in.readString();
        this.mediaType = in.readInt();
    }

    public static final Creator<Photo> CREATOR = new Creator<Photo>() {
        @Override
        public Photo createFromParcel(Parcel source) {
            return new Photo(source);
        }

        @Override
        public Photo[] newArray(int size) {
            return new Photo[size];
        }
    };
}
